//
// Created by tcj on 2022/2/25.
//

#include "sylar/sylar.h"
sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();


void test_fiber(){
    static int c_count =5;
    SYLAR_LOG_INFO(g_logger)<<"test in fiber c_count="<<c_count;

//    sleep(1);
    if(--c_count>=0){
        std::cout<<"c_count="<<c_count<<std::endl;
//        std::cout<<std::endl;
        sylar::Scheduler::GetThis()->schedule(&test_fiber,sylar::GetThreadId());
    }

}


void func_1(){
    SYLAR_LOG_INFO(g_logger)<<"funct_1  testing";
}

void func_2(){
    SYLAR_LOG_INFO(g_logger)<<"funct_2  testing";
}

int main(int argc,char** argv){
//    SYLAR_LOG_INFO(g_logger)<<"main";
//    sylar::Scheduler sc(1, true,"test");
//    sc.start();
//    SYLAR_LOG_INFO(g_logger)<<"schedule";
//    sc.schedule(&test_fiber);
//    sc.stop();
//    SYLAR_LOG_INFO(g_logger)<<"over";


    SYLAR_LOG_INFO(g_logger)<<"test begin";
    sylar::Scheduler sc(1, true,"test");
    sc.schedule(&func_1);
    sylar::Fiber::ptr p(new sylar::Fiber(&func_2));
    sc.schedule(p);
    SYLAR_LOG_INFO(g_logger)<<"begin schendule";
    sc.start();
    sc.stop();
    SYLAR_LOG_INFO(g_logger)<<"test end";
    return 0;
}

